package com.easydict.core;

import com.easydict.annotation.EasyDict;
import com.easydict.spi.DictionaryResolver;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;

/**
 * 写入器创建上下文
 * 封装创建写入器所需的所有信息
 */
public class WriterCreationContext {
    
    private final BeanPropertyWriter originalWriter;
    private final EasyDict annotation;
    private final DictionaryResolver resolver;
    private final SerializationContext serializationContext;
    private final String factoryVersion;
    private final long creationTimestamp;
    
    private WriterCreationContext(Builder builder) {
        this.originalWriter = builder.originalWriter;
        this.annotation = builder.annotation;
        this.resolver = builder.resolver;
        this.serializationContext = builder.serializationContext;
        this.factoryVersion = builder.factoryVersion;
        this.creationTimestamp = System.currentTimeMillis();
    }
    
    public BeanPropertyWriter getOriginalWriter() {
        return originalWriter;
    }
    
    public EasyDict getAnnotation() {
        return annotation;
    }
    
    public DictionaryResolver getResolver() {
        return resolver;
    }
    
    public SerializationContext getSerializationContext() {
        return serializationContext;
    }
    
    public String getFactoryVersion() {
        return factoryVersion;
    }
    
    public long getCreationTimestamp() {
        return creationTimestamp;
    }
    
    public static Builder builder() {
        return new Builder();
    }
    
    public static class Builder {
        private BeanPropertyWriter originalWriter;
        private EasyDict annotation;
        private DictionaryResolver resolver;
        private SerializationContext serializationContext;
        private String factoryVersion;
        
        public Builder originalWriter(BeanPropertyWriter originalWriter) {
            this.originalWriter = originalWriter;
            return this;
        }
        
        public Builder annotation(EasyDict annotation) {
            this.annotation = annotation;
            return this;
        }
        
        public Builder resolver(DictionaryResolver resolver) {
            this.resolver = resolver;
            return this;
        }
        
        public Builder serializationContext(SerializationContext serializationContext) {
            this.serializationContext = serializationContext;
            return this;
        }
        
        public Builder factoryVersion(String factoryVersion) {
            this.factoryVersion = factoryVersion;
            return this;
        }
        
        public WriterCreationContext build() {
            return new WriterCreationContext(this);
        }
    }
}
